#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  02-dracut.sh
# Version	:  2.0
# Date		:  2024/04/26
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinsec.com.cn
# Function	:  dracut测试
# Out		:
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="dracut测试"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB() {
    return $TPASS
}

## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB() {
    return $TPASS
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB() {
    testcase_1
    return $TPASS
}

## TODO : dracut测试
testcase_1() {
    local initramfs_name=$(ls -lah /boot | grep "initramfs" | grep "$(arch).img" | awk '{print $NF}')
    rm -rf "${initramfs_name}"
    CommRetParse_LTFLIB "rm -rf ${initramfs_name}成功"
    dracut -f
    CommRetParse_LTFLIB "dracut -f"
    local initramfs_name_dracut=$(ls -lah /boot | grep "initramfs" | grep "$(arch).img" | awk '{print $NF}')
    if [[ "${initramfs_name}" == "${initramfs_name_dracut}" ]]; then
        OutputRet_LTFLIB ${TPASS}
        TestRetParse_LTFLIB "dracut -f ${initramfs_name_dracut}生成成功"
    else
        OutputRet_LTFLIB ${TFAIL}
        TestRetParse_LTFLIB "dracut -f ${initramfs_name_dracut}生成失败"
    fi

}

#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
